package com.mxbbx.wdn.domain.medical;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.mxbbx.wdn.database.DBUtil;

/**
 * 基础数据模块类
 * 
 * @author 
 * 
 */
public class Data {

	private int id;
	private String dataCode;
	private String dataName;
	private String type;

	public Data() {

	}

	public Data(String dataCode, String type) throws Exception {
		if (dataCode == null || type == null) {
			throw new IllegalStateException("参数不能为null");
		}
		this.dataCode = dataCode;
		this.type = type;
		load();
	}

	public void load() throws SQLException {
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		try {
			String sql = "select * from data where dataCode=? and type=?";
			conn = DBUtil.getConn();
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, this.dataCode);
			pstmt.setString(2, this.type);
			rs = pstmt.executeQuery();
			if (rs.next()) {
				this.id = rs.getInt(1);
				this.dataCode = rs.getString(2);
				this.dataName = rs.getString(3);
			}
		} catch (SQLException e) {
			e.printStackTrace();
			throw e;
		}finally {
			DBUtil.close(rs, pstmt, conn);
		}
	}

	public Data(String dataCode, String dataName, String type) {
		super();
		this.dataCode = dataCode;
		this.dataName = dataName;
		this.type = type;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getDataCode() {
		return dataCode;
	}

	public void setDataCode(String dataCode) {
		this.dataCode = dataCode;
	}

	public String getDataName() {
		return dataName;
	}

	public void setDataName(String dataName) {
		this.dataName = dataName;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

}
